package com.blogSystem.sms.listener;

import com.aliyuncs.exceptions.ClientException;
import com.blogSystem.sms.util.SmsUtil;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RabbitListener(queues = "sms_change")
public class SmsChangeListener {
    @Value("${aliyun.sms.sign_name}")
    private String sign_name;

    @Value("${aliyun.sms.template_code_change}")
    private String template_code;

    @Autowired
    private SmsUtil smsUtil;
    @RabbitHandler
    public  void executeSms(Map<String,String> map){
        System.out.println("手机号："+map.get("mobile"));
        System.out.println("验证码："+map.get("checkcode"));
        String code=map.get("checkcode");
        try {

            smsUtil.sendSms(map.get("mobile"),template_code,sign_name,"{\"code\":\""+code+"\"}");

        } catch (ClientException e) {
            System.out.println(e.getErrMsg());
        }
    }
}
